﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using CLab.BusinessEntity;
using GandA.Component.DataAccess.SQLServer;

namespace CLab.DAO
{
    public static class ConsultaServiceDAO
    {
        public static DataSet EjecutaConsulta(string nombreStoredProcedure, Parameter[] parametros)
        {
            SQLParameterCollection paramsSql = new SQLParameterCollection();

            if (parametros != null)
            {
                foreach (Parameter param in parametros)
                {
                    paramsSql.Add(new SQLParameter(param.NombreParametro, param.Valor, (SQLParameter.vEnumSqlDbType)param.Type, SQLParameter.vEnumParameterDirection.vInput));
                }

                try
                {
                    return new SQL().ExecuteQuerySP(nombreStoredProcedure, paramsSql);
                }
                catch(SQLException ex)
                {
                    throw new Exception(ex.Message);
                }
            }
            else
            {
                return new SQL().ExecuteQuerySP(nombreStoredProcedure);
            }
        }
    }
}
